<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

if(isset($_POST)) {

    $username = $_POST['username'];
    $password = $_POST['password'];
    $xmlFile = file_get_contents("./xml/users.xml");
    $xml = new SimpleXMLElement($xmlFile);
    //Ueberpruefen ob Logindaten korrekt sind
    $login = false;
    if($xml) {
        foreach($xml->user as $user) {
            if($user->username == $username && $user->password = $password && $user->attributes->deleted != true) {
                $login = true;
            }
        }
    }
    if(!$login) {
        echo "Logindaten nicht korrekt.";
    }
}

if($login) {
    session_start();
    $_SESSION['user'] = $username;
    generate_output();
}

function generate_output() {
    echo "<a href=\"insert.php\" target=\"_new\">Insert Data</a>\n";
    echo "<a href=\"view.php\" target=\"_new\">View Data</a>\n";
}
?>
